﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>"/>
<link rel="shortcut icon" href="images/store.png" /><!--图片log  -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<link href="css/base.css" rel="stylesheet">
<link href="css/shopcar.css?v=0512" rel="stylesheet">
<script src="js/jquery-1.8.3.min.js"></script>
<script src="js/shop.js?v=0512"></script>
<title>在线支付</title>
    <script>
    $(document).ready(function () {
        var code = shop.getParam("code");
        var openid = shop.getLocalStorage("openid");//先从本地中取得openid
        if(openid == ""||openid == undefined){//判断openid是否存在，如果不存在就执行ajax获取数据
	        if (code !== "" && code != undefined) {
	           $(".loading-all").hide();
	           $("body").show();
	           $.ajax({
	                url: 'WeiXin/GetOpenId',
	                data: JSON.stringify({code:code}),
	                type: 'post',
	                contentType:"application/json;charset=utf-8",
	                success: function (data) {
	                	//alert(data);
	                	shop.setLocalStorage("openid", data);
	                }
	            }); 
	        }
	        else {
	            var platformcode = "100001";
	            var url = location.href;
	            url = shop.getTokenSite() + "/Token/GetCodeRedirectUri?platformcode=" + platformcode + "&rebackUri=" + encodeURIComponent(url) + "&funcname=callback";
	            location.href = url;
	        }
        }
    }); 
    </script>
</head>
<body>
    <input type="hidden" id="focusme" value="focus">
    <header></header>
    <div class="by_w" id="by_w">
        <div class="m_pagetop" align="center">
            <span class="m_goback" onclick="document.location.href = 'javascript:history.go(-1)';"></span>
            <span class="m_title">在线支付</span>
        </div>
        <div class="m_wap" id="min_hdiv" style="min-height: 448px;">
            <div class="m_ddd">
                <table width="100%" cellpadding="0" cellspacing="12px" border="0" class="pay_tab">
                    <tbody>
                        <tr>
                            <th style="min-width:80px" width="20%" align="right">应付金额：</th>
                            <th width="80%" align="left">
                                <span class="f60" id="dd_price">￥${custOrder.FAmount}</span>
                            </th>
                        </tr>
                        <tr>
                            <th align="right" valign="top" id="adrname">收货信息：</th>
                            <td align="left" id="address" style="word-break: break-word;">
                            	<!-- 联系人 联系电话 省份 市 县 地址 -->
                            	${user.contactperson}&nbsp;&nbsp;&nbsp;&nbsp;
                            	${user.contacttel}<br/>
                            	${user.address}<br/>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="m_ddp">
                请选择支付方式&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="fk_ts">请在20分钟内完成支付</span>
            </div>
            <div style="text-align:left; background-color:#fff;width:80%;margin:0 auto;position:fixed;left:10%;top:50%;display:none;height:47px;line-height:47px" class="wait">
                <img src="images/waiting.jpg" style="width:28px; display:inline-block; margin-left:20px; margin-top:10px; float:left;" />
                <span style="line-height:47px;display:inline-block; margin-left:20px;">正在生成支付链接，请稍等</span>
            </div>
            <!-- 微信WAP支付 -->
            <div class="pay_zf ofh" id="pay_wx_wap">
                <span class="wxzf_pic f_l"></span>
            </div>

            <!--支付按钮-->
            <form id="JsApiPayForm" name="JsApiPayForm" method="POST" target="_self">
                <input type="hidden" id="platformcode" name="platformcode" />
                <input type="hidden" id="signparameter" name="signparameter" />
                <input type="hidden" id="parameter" name="parameter" />
            </form>
            
		    <div><jsp:include page="part/foot.jsp"></jsp:include></div>
        </div>

        <script type="text/javascript">
            $("#pay_wx_wap").click(function () {
                var openid = shop.getLocalStorage("openid");
                var sid = '${sid}';
                var platformcode = "100001";
                var totalfee='${custOrder.FAmount}';
                $(".wait").show();
                $.ajax({
                    url: 'WeiXin/WxJsApiPay',
                    type: 'post',
                    contentType:"application/json;charset=utf-8",
                    data: JSON.stringify({ platformcode: platformcode, openid: openid, sid: sid,totalfee:totalfee }),
                    //dataType:'json',
                    success: function (data) {
                    	//alert(data);
                        if (data!="") {
                            $(".wait").hide();
                            $("#parameter").val(data);
                            $("#platformcode").val("100001");
                            $("#JsApiPayForm").attr("action", shop.getPaySite() + "/PayPages/JsApiPay.aspx?showwxpaytitle=1");
                            //alert(shop.getPaySite() + "/PayPages/JsApiPay.aspx?showwxpaytitle=1");
                            $("#JsApiPayForm").submit();
                        } else {
                            alert("支付失败！");
                        } 
                    },
                    error: function (e) {
                        alert("网络出错！");
                    }
                });
            });
        </script>
    </div>
</body>
</html>